import { Router } from 'express';
import { DeviceController } from '../controllers/DeviceController';
import { validateDeviceId, validateRequest, rateLimiter } from '../middlewares/validation';

const router: Router = Router();
const deviceController = new DeviceController();

// 应用限流中间件
router.use(rateLimiter(200, 60000)); // 每分钟最多200个请求

// 设备相关路由
router.get('/devices', deviceController.getDevices.bind(deviceController));

router.get('/devices/:deviceId/data', 
  validateDeviceId,
  deviceController.getDeviceData.bind(deviceController)
);

router.get('/devices/:deviceId/stats', 
  validateDeviceId,
  deviceController.getDeviceStats.bind(deviceController)
);

router.post('/devices/:deviceId/commands', 
  validateDeviceId,
  validateRequest(['command']),
  deviceController.sendCommand.bind(deviceController)
);

export default router;
